package com.lhj.jpa.future;

import java.util.concurrent.CompletableFuture;

/**
 * thenCompose 第二个线程依赖第一个线程的结果
 * @author linghaijin781
 * @date 2021/9/2210:04 下午
 */
public class _01_thenCompose {
	public static void main(String[] args) {
		SmallTool.printTimeAndThread("小白进入餐厅");
		SmallTool.printTimeAndThread("小白点了 番茄炒蛋 + 一碗米饭");

		CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
			SmallTool.printTimeAndThread("厨师炒菜");
			SmallTool.sleepMills(200);

			return "番茄炒蛋";
		}).thenCompose(dish -> CompletableFuture.supplyAsync(() -> {

			SmallTool.printTimeAndThread("服务员打饭");
			SmallTool.sleepMills(100);
			return dish + "盖浇饭，做好了";
		}));

		SmallTool.printTimeAndThread("小白在打王者荣耀");
		SmallTool.printTimeAndThread(String.format("%s, 小白开吃", cf1.join()));
	}
}
